package logic

import (
	"cloud-disk/core/helper"
	"cloud-disk/core/internal/svc"
	"cloud-disk/core/internal/types"
	"cloud-disk/core/model"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserRepostiorySaveLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserRepostiorySaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserRepostiorySaveLogic {
	return &UserRepostiorySaveLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserRepostiorySaveLogic) UserRepostiorySave(req *types.UserRepostiorySaveRequest, UserIdentity string) (resp *types.UserRepostiorySaveResponse, err error) {
	resp = new(types.UserRepostiorySaveResponse)
	ur := model.UserRepostiory{
		Identity:           helper.GetUUID(),
		UserIdentity:       UserIdentity,
		ParentId:           req.ParentId,
		ReoisitoryIdentity: req.ReoisitoryIdentity,
		Ext:                req.Ext,
		Name:               req.Name,
	}

	err = l.svcCtx.UserRepostioryModel.CreateUserRepostiory(&ur)
	if err != nil {
		resp.Message = "保存失败"
		resp.Code = 100
		return resp, nil
	}

	resp.Message = "保存成功"
	resp.Code = 200
	resp.Identity = ur.Identity
	return resp, nil
}
